﻿using System;
using System.IO;
using System.Web;

namespace OutOfMemoryException
{
    public static class LogHelper
    {
        /// <summary>
        /// 写日志(用于跟踪)
        /// </summary>
        public static void WriteLog(string strMemo)
        {
            var startupPath = System.Windows.Forms.Application.StartupPath;
            string filename = startupPath + "/logs" + "/" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";//用日期对日志文件命名

            if (!Directory.Exists(startupPath + "//logs//"))
                Directory.CreateDirectory(startupPath + "//logs//");
            StreamWriter sr = null;
            try
            {
                if (!File.Exists(filename))
                {
                    sr = File.CreateText(filename);
                }
                else
                {
                    sr = File.AppendText(filename);
                }
                sr.WriteLine("----------------------------- {0} -----------------------------", DateTime.Now);
                sr.WriteLine(strMemo);
                sr.Flush();
                sr.WriteLine("-------------------------------------------------------------------------");
            }
            catch
            {
            }
            finally
            {
                if (sr != null)
                    sr.Close();
            }
        }


    }

}
